package com.sofa.shark.common.log.apm;

import com.alipay.sofa.rpc.common.RpcConstants;
import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
import com.sofa.shark.admin.api.fegin.RemoteLogService;
import com.sofa.shark.common.log.apm.aspect.SysLogAspect;
import com.sofa.shark.common.log.apm.event.SysLogListener;
import com.sofa.shark.common.log.apm.logfactory.ApmLoggerFactory;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author tonyp
 */
@Configuration
@EnableAsync
@AllArgsConstructor
@ConditionalOnWebApplication
public class SharkCommonLogConfig {
    @SofaReference(interfaceType = RemoteLogService.class, binding = @SofaReferenceBinding(bindingType = RpcConstants.PROTOCOL_TYPE_BOLT))
    private RemoteLogService remoteLogService;

    @Bean
    public SysLogAspect sysLogAspect() {
        return new SysLogAspect();
    }

    @Bean
    public SysLogListener sysLogListener() {
        return new SysLogListener(remoteLogService);
    }

}
